package org.csu.mypetstore.persistence;

import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.csu.mypetstore.domain.Product;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface ProductMapper {
    @Select("        SELECT\n" +
            "            PRODUCTID,\n" +
            "            NAME,\n" +
            "            DESCN as description,\n" +
            "            IMAGE,\n" +
            "            CATEGORY as categoryId\n" +
            "        FROM PRODUCT\n" +
            "        WHERE CATEGORY = #{value}")
    List<Product> getProductListByCategory(String categoryId);

    @Select("        SELECT\n" +
            "            PRODUCTID,\n" +
            "            NAME,\n" +
            "            DESCN as description,\n" +
            "            IMAGE,\n" +
            "            CATEGORY as categoryId\n" +
            "        FROM PRODUCT\n" +
            "        WHERE PRODUCTID = #{productId}")
    Product getProduct(String productId);

    @Select("        select\n" +
            "            PRODUCTID,\n" +
            "            NAME,\n" +
            "            DESCN as description,\n" +
            "            IMAGE,\n" +
            "            CATEGORY as categoryId\n" +
            "        from PRODUCT\n" +
            "        WHERE lower(name) like #{value}")
    List<Product>searchProductList(String keywords);

    @Select("        select\n" +
            "            *,\n" +
            "            DESCN as description,\n" +
            "            CATEGORY as categoryId\n" +
            "        from product")
    List<Product>getAllProduct();
}
